package com.ybkj.o2o.mc.common.transport;

import com.ybkj.o2o.mc.entity.Passenger;
import com.ybkj.o2o.mc.entity.PassengerAddress;
import com.fasterxml.jackson.annotation.JsonProperty;

import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by shine on 16/9/14.
 */
public class PassengerAddressResult {

  private Long id;

  private String address;    //常用地址

  private String addressDetail;//详细地址

  private Double latitude;  //纬度

  private Double longitude;  //经度

  private Integer type;    //类型:0家,1公司,2其他

  @JsonProperty("passenger_id")
  private Long passengerId;  //乘客Id

  private Date created;

  private Date updated;

  @JsonProperty(value = "passenger_name")
  private String passengerName;

  @JsonProperty(value = "passenger_phone")
  private String passengerPhone;

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public String getAddress() {
    return address;
  }

  public void setAddress(String address) {
    this.address = address;
  }

  public String getAddressDetail() {
    return addressDetail;
  }

  public void setAddressDetail(String addressDetail) {
    this.addressDetail = addressDetail;
  }

  public Double getLatitude() {
    return latitude;
  }

  public void setLatitude(Double latitude) {
    this.latitude = latitude;
  }

  public Double getLongitude() {
    return longitude;
  }

  public void setLongitude(Double longitude) {
    this.longitude = longitude;
  }

  public Integer getType() {
    return type;
  }

  public void setType(Integer type) {
    this.type = type;
  }

  public Long getPassengerId() {
    return passengerId;
  }

  public void setPassengerId(Long passengerId) {
    this.passengerId = passengerId;
  }

  public Date getCreated() {
    return created;
  }

  public void setCreated(Date created) {
    this.created = created;
  }

  public Date getUpdated() {
    return updated;
  }

  public void setUpdated(Date updated) {
    this.updated = updated;
  }

  public String getPassengerName() {
    return passengerName;
  }

  public void setPassengerName(String passengerName) {
    this.passengerName = passengerName;
  }

  public String getPassengerPhone() {
    return passengerPhone;
  }

  public void setPassengerPhone(String passengerPhone) {
    this.passengerPhone = passengerPhone;
  }

  /**
   * 把PassengerAddress类型转换为PassengerAddressResult用于输出.
   *
   * @param addresses 联系人信息
   */
  public static List<PassengerAddressResult> convertFrom(List<PassengerAddress> addresses) {

    return addresses.stream().map(address -> convertFrom(address)).collect(Collectors.toList());

  }

  /**
   * 把PassengerAddress类型转换为PassengerAddressResult用于输出.
   *
   * @param address 常用目的地
   */
  public static PassengerAddressResult convertFrom(PassengerAddress address) {

    PassengerAddressResult result = new PassengerAddressResult();

    BeanUtils.copyProperties(address, result, "passenger", "passengerName",
            "passengerPhone", "passengerId");

    result.setPassengerId(address.getPassengerId());

    Passenger passenger = address.getPassenger();
    if (null != passenger) {
      result.setPassengerName(passenger.getName());
      result.setPassengerPhone(passenger.getPhone());
    }

    return result;
  }
}
